package br.com.seosoft.simplecalcfinan;

import com.google.analytics.tracking.android.EasyTracker;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SolicitarSenha extends Activity {
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */

	private EditText senha;
	private Button botaoEntrar;
	private SharedPreferences preference;
	private String email, passwordSalvo, passwordDigitado, Clasz;
	Intent it;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		// Veririfica versao
		if (VERSION.SDK_INT > 14) {

			setTheme(android.R.style.Theme_DeviceDefault_Light);

		}
		if (VERSION.SDK_INT == 14) {
			setTheme(android.R.style.Theme_Holo_Light);

		}
		super.onCreate(savedInstanceState);

		it = getIntent();

		Clasz = it.getStringExtra("class");

		preference = PreferenceManager
				.getDefaultSharedPreferences(getApplicationContext());
		passwordSalvo = preference.getString("password", null);
		email = preference.getString("email", null);

		setContentView(R.layout.solicitar_senha);
		senha = (EditText) findViewById(R.soliSenha.etSenha);
		botaoEntrar = (Button) findViewById(R.soliSenha.btnOk);

		botaoEntrar.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				passwordDigitado = senha.getText().toString();

				Log.v(geral.LogCat, "nome da class recebida : " + Clasz);

				if (passwordDigitado.equals(passwordSalvo)) {

					geral.logado = true;

					if (Clasz.equals(ImportarCsvIntent.class.getName())) {

						startActivity(new Intent(getApplicationContext(),
								ImportarCsvIntent.class).setData(it.getData())
								.replaceExtras(it));

					} else {
						startActivity(new Intent(getApplicationContext(),
								inicial.class)
								.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
					}

				} else {
					senha.setError(getResources().getString(
							R.string.senhaNaoConfere));
				}

			}
		});

	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		EasyTracker.getInstance().activityStart(this);
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		EasyTracker.getInstance().activityStop(this);
	}
}
